package com.ctsi.organise.service;

import com.ctsi.commons.util.UtilValidate;
import com.ctsi.commons.util.id.UUIDGenerator;
import com.ctsi.commons.util.response.Page;
import com.ctsi.framework.mybatis.support.MybatisGenericDao;
import com.ctsi.organise.entity.PersonGW;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;

import java.util.Map;

/**
 * @auth:wgf
 * @description :
 * @Date: 2019/3/15
 */
@Repository
public class PersonGwService {
    private static final Logger logger= LoggerFactory.getLogger(PersonGwService.class);
    @Autowired
    private MybatisGenericDao dao;
    /**
     * 添加
     */
    public int insertPersonGw(PersonGW personGW){
        if(UtilValidate.isEmpty(personGW.getId()))
            personGW.setId(UUIDGenerator.getId());
        logger.debug("insert {}",personGW);
       return dao.insert(personGW);
    }
    /**
     * 动态更新
     */
    public int updatePersonGwByPKSelective(PersonGW personGW){
        logger.debug("updateByPrimaryKeySelective {}",personGW);
        return dao.update(PersonGW.class.getName()+".updateByPrimaryKeySelective", personGW);
    }
    /**
     * 根据ID查询岗位详情
     */
    public PersonGW findPersonGWById(String id){
        if(UtilValidate.isEmpty(id))
            return null;
        logger.debug("findById {}",id);
        return dao.get(PersonGW.class, id);
    }
    /**
     * 根据ID删除岗位
     */
    public int deletePersonGwById(String id){
        if(UtilValidate.isNotEmpty(id)){
            return dao.delete(PersonGW.class.getName()+".delete", id);
        }
        return 0;
    }

    /**
     *  根据PersonID查询岗位列表
     */
    public Page<PersonGW> queryListPersonGW(Map<String,Object> param , int start , int pageSize){
        logger.debug("selectMulitCondition {}",param);
        if(pageSize<0||pageSize>2000)
            pageSize=Page.DEFAULT_PAGE_SIZE;
        if(start!=-1)
            return dao.queryPage(PersonGW.class.getName()+".selectMulitCondition", param, start, pageSize);
        else{
            throw new RuntimeException("参数不正确 !!");
        }
    }
}

